import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { TilePanel } from "../equipment/TilePanel";
import { CountryFriendCellRenderer } from "./CountryFriendCellRenderer";
import { Cache } from "../../cache/Cache";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { Alert } from "../../../../com/mui/controls/Alert";
import { ECountryPositionOperType } from "../../../../Message/Game/ECountryPositionOperType";
import { ECountryPosition } from "../../../../Message/Game/ECountryPosition";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { FriendInfo } from "../../model/FriendInfo";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class CountryPositionOperWindow
    
    export  class CountryPositionOperWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._friendInfoArr = [];
            setSize(465, 375);
            title = Language.getString(36446);
            titleHeight = 30;
            return;
        }

        public set position(arg1: int)
        {
            this._position = arg1;
            return;
        }

        public set posName(arg1: string)
        {
            this._posName = arg1;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(18, 45, 429, 315, this);
            ObjCreate.createBg(25, 73, 400, 2, this, ImagesConst.SplitLine);
            ObjCreate.createGTextField(Language.getString(36447), 55, 50, 90, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createGTextField(Language.getString(36448), 145, 50, 40, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createGTextField(Language.getString(36449), 205, 50, 30, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createGTextField(Language.getString(36450), 245, 50, 50, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createGTextField(Language.getString(36451), 330, 50, 50, 20, this, GlobalStyle.textFormat2);
            this._friendTileList = new TilePanel();
            this._friendTileList.setSize(420, 240);
            this._friendTileList.rowHeight = 30;
            this._friendTileList.columnWidth = 400;
            this._friendTileList.setStyle("cellRenderer", CountryFriendCellRenderer);
            this._friendTileList.move(25, 75);
            this.addChild(this._friendTileList);
            this._friendInfoArr = Cache.instance.friend.getFriendArrayList();
            this._friendTileList.dataProvider = new DataProvider(this._friendInfoArr);
            this._appointBtn = ObjCreate.createGButton(Language.getString(36452), 350, 325, 80, 25, this);
            this._appointBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAppointBtnClickHandler);
            return;
        }

        /* internal  */onAppointCloseHandler(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            if (arg1 == Alert.OK) 
            {
                loc1 = ECountryPositionOperType.convert(ECountryPositionOperType._ECountryPositionOperTypeAppoint);
                loc2 = this._friendInfo.friendPlayerInfo.playerId;
                loc3 = ECountryPosition.convert(this._position);
                loc4 = {"fromPlayerId": 0, "toPlayerId": loc2, "operType": loc1, "targetPosition": loc3};
                if (loc2 != 0) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CountryOperPosition, loc4));
                }
            }
            return;
        }

        /* internal  */onAppointBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._friendInfo = this._friendTileList.selectedItem as FriendInfo;
            if (this._friendInfo == null) 
            {
                return;
            }
            var loc1=this._friendInfo.friendPlayerInfo.playerName;
            var loc2=this._posName;
            var loc3=Language.getStringByParam(36453, loc1, loc2);
            Alert.show(loc3, null, Alert.OK | Alert.CANCEL, null, this.onAppointCloseHandler);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show();
            this.updateFriendList();
            return;
        }

        public updateFriendList(): void
        {
            this._friendInfoArr = Cache.instance.friend.getFriendArrayList();
            this._friendTileList.dataProvider = new DataProvider(this._friendInfoArr);
            return;
        }

        /* internal */ /* var */_friendTileList: TilePanel;

        /* internal */ /* var */_friendInfoArr: Array<any>;

        /* internal */ /* var */_appointBtn: GButton;

        /* internal */ /* var */_position: int;

        /* internal */ /* var */_posName: string="";

        /* internal */ /* var */_friendInfo: FriendInfo;
    }
